﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FileList.aspx.cs" Inherits="UDS.WebApp.SubModule.PersonalFileListPage" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
  <title>File List Page</title>
  <uds:Style ID="Style1" runat="server" Href="~/css/BasicLayout.css" />
  <uds:CommonJScript runat="server" EnableJQuery="true" />
  <script type="text/javascript">
  //<!--
  var g_directoryId = parseInt('<%= Current.Id %>', 10);

  function create_directory() {
    var on_fail = function(err) {
      alert("创建目录失败：" + err.get_message());
    };

    var name = $.trim($("#<%= tb_DirectoryName.ClientID %>").val());
    if (name.length > 0) {
      UDS.WebApp.SubModule.PFService.CreateDirectory(g_directoryId, name, do_refresh, on_fail);
    }
    else {
      alert("请输入目录名称");
    }
  }

  function do_refresh() {
    // refresh the current page
    window.location.href = window.location.href;
  }

  function delete_directory(directoryId) {
    if (!window.confirm("您确实要删除此目录吗？"))
      return;
    var on_fail = function(err) {
      alert("删除目录失败：" + err.get_message());
    };
    UDS.WebApp.SubModule.PFService.DeleteDirectory(directoryId, do_refresh, on_fail);
  }

  function delete_file(fileId) {
    if (!window.confirm("您确实要删除此文件吗？"))
      return;
    var on_fail = function(err) {
      alert("删除文件失败：" + err.get_message());
    };
    UDS.WebApp.SubModule.PFService.DeleteFile(fileId, do_refresh, on_fail);
  }
  //-->
  </script>
</head>
<body>
  <form id="Form1" method="post" runat="server">
  <asp:ScriptManager runat="server">
    <services>
      <asp:ServiceReference path="PFService.asmx" />
    </services>
  </asp:ScriptManager>
  <uds:PageTitle ID="PageTitle1" runat="server" HintImage="~/images/icon/284.GIF">
    <TitlePanel>网络存储 &#187; <%= HttpUtility.HtmlEncode( Current.Name ) %> </TitlePanel>
    <RightPanel><a href="javascript:void(0)" onblur="upload_file()"><b>上传文件</b></a> </RightPanel>
  </uds:PageTitle>
  <div style="padding: 8px;">
    <table cellspacing="0" cellpadding="0" width="100%" border="0" class="formtable">
      <tr>
        <td width="100" class="formlabel">创建子目录 </td>
        <td>
          <asp:TextBox runat="server" ID="tb_DirectoryName" CssClass="normalInput" />
          <input type="button" value="确定" class="optionbutton redButtonCss" onclick="create_directory()" />
        </td>
      </tr>
      <tr>
        <td class="formlabel">上传文件 </td>
        <td>
          <asp:FileUpload runat="server" ID="fileUpload" Width="400px" />
          <asp:RequiredFieldValidator runat="server" ErrorMessage="(*)" ControlToValidate="fileUpload" />
          <asp:Button runat="server" ID="btn_Upload" Text="上传" CssClass="optionbutton redButtonCss" />
        </td>
      </tr>
    </table>
  </div>
  <table class="datagrid fixedtable">
    <tr class="datagrid_header">
      <td style="width: 100%;">名称</td>
      <td style="width: 120px;">更新时间</td>
      <td style="width: 80px;">类型</td>
      <td style="width: 100px;">大小</td>
      <td style="width: 80px;">删除</td>
    </tr>
    <tr runat="server" id="parentDirectoryRow" class="datagrid_row">
      <td><a href="FileList.aspx?DirectoryId=<%= Current.ParentId %>" title="跳转至上级目录">..</a> </td>
      <td>&nbsp; </td>
      <td>目录 </td>
      <td>&nbsp; </td>
      <td>&nbsp; </td>
    </tr>
    <asp:Repeater runat="server" ID="directoryRepeater" EnableViewState="false">
      <ItemTemplate>
        <tr class="datagrid_row">
          <td><a href="FileList.aspx?DirectoryId=<%# ((PFDirectoryInfo)Container.DataItem).Id%>"><%# HttpUtility.HtmlEncode( ((PFDirectoryInfo)Container.DataItem).Name ) %></a> </td>
          <td>&nbsp; </td>
          <td>目录 </td>
          <td>&nbsp; </td>
          <td><a href="javascript:void(0);" onclick="delete_directory(<%# ((PFDirectoryInfo)Container.DataItem).Id%>);">删除</a> </td>
        </tr>
      </ItemTemplate>
    </asp:Repeater>
    <asp:Repeater runat="server" ID="fileRepeater" EnableViewState="false">
      <ItemTemplate>
        <tr class="datagrid_row">
          <td><a href="DownloadFile.aspx?FileId=<%# ((PFFileInfo)Container.DataItem).Id%>"><%# HttpUtility.HtmlEncode(((PFFileInfo)Container.DataItem).Name)%></a> </td>
          <td><span class="date"><%# Utility.FormatDateTime(((PFFileInfo)Container.DataItem).LastModified)%></span> </td>
          <td>文件 </td>
          <td><%# FormatFileSize( ((PFFileInfo)Container.DataItem).Size ) %> </td>
          <td><a href="javascript:void(0);" onclick="delete_file(<%# ((PFFileInfo)Container.DataItem).Id %>)">删除</a> </td>
        </tr>
      </ItemTemplate>
    </asp:Repeater>
  </table>
  </form>
</body>
</html>
